﻿using System;
using System.Reflection;
using Glue.Internals;

namespace GlueTests.Builders
{
    internal class PropertyBuilder
    {
        public class BaseClass
        {
            public NestedClass NestedProperty { get; set; }
            public bool BooleanProperty { get; set; }
            public bool? NullableBooleanProperty { get; set; }
            public double DoubleProperty { get; set; }
            public double NullableDoubleProperty { get; set; }
            public String StringProperty { get; set; }
            public int IntProperty { get; set; }
            public int[] IntArrayProperty { get; set; }

            public class NestedClass { }
        }

        private readonly Type type;
        private readonly string propertyName;
        private readonly ObjectMemberFactory factory = new ObjectMemberFactoryBuilder().Build();

        public static PropertyBuilder AsNestedProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "NestedProperty");
        }

        public static PropertyBuilder AsBooleanProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "BooleanProperty");
        }

        public static PropertyBuilder AsNullableBooleanProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "NullableBooleanProperty");
        }

        public static PropertyBuilder AsDoubleProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "DoubleProperty");
        }

        public static PropertyBuilder AsNullableDoubleProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "NullableDoubleProperty");
        }

        public static PropertyBuilder AsStringProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "StringProperty");
        }

        public static PropertyBuilder AsIntProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "IntProperty");
        }

        public static PropertyBuilder AsIntArrayProperty()
        {
            return new PropertyBuilder(typeof(BaseClass), "IntArrayProperty");
        }

        
        public PropertyBuilder(Type type, String propertyName)
        {
            this.type = type;
            this.propertyName = propertyName;
        }

        public IObjectMember Build()
        {
            return factory.CreateObjectMember(type.GetProperty(propertyName,
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
        }



    }
}
